// 如果没有通过拦截器配置域名的话，可以在这里写上完整的URL(加上域名部分)
let hotSearchUrl = '/ebapi/store_api/hot_search';
let indexUrl = '/ebapi/public_api/index';
// 发短信接口
let smsSendUrl = 'sms/send';
// 注册登录接口
let userMobileLoginUrl = 'user/mobilelogin';
// 修改用户信息接口
let userProfileUrl = 'user/profile';
// 获取用户信息
let userGetUserInfoUrl = 'user/getUserInfo';
// 退出登录
let userLogoutUrl = 'user/logout';
// 车辆列表
let carListUrl = 'cars/carList';
// 车辆详情
let carDetailUrl = 'cars/detail';
// 获取车辆分类
let getCarCategoryUrl = 'cars/getCarCategory';
// 提交订单
let submitOrderUrl = 'order/submitOrder';
// 取消订单
let cancelOrderUrl = 'order/cancelOrder';
// 订单列表
let orderListUrl = 'order/orderList';

// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
const install = (Vue, vm) => {
	// 此处没有使用传入的params参数
	let getSearch = (params = {}) => vm.$u.get(hotSearchUrl, {
		id: 2
	});
	// 此处使用了传入的params参数，一切自定义即可
	let getInfo = (params = {}) => vm.$u.post(indexUrl, params);

	let smsSend = (params = {}) => vm.$u.post(smsSendUrl, params);

	let userMobileLogin = (params = {}) => vm.$u.post(userMobileLoginUrl, params);

	let userProfile = (params = {}) => vm.$u.post(userProfileUrl, params);

	let getUserInfo = (params = {}) => vm.$u.post(userGetUserInfoUrl, params);

	let userLogout = (params = {}) => vm.$u.post(userLogoutUrl, params);

	let carList = (params = {}) => vm.$u.post(carListUrl, params);

	let carsDetail = (params = {}) => vm.$u.post(carDetailUrl, params);

	let getCarCategory = (params = {}) => vm.$u.post(getCarCategoryUrl, params);

	let submitOrder = (params = {}) => vm.$u.post(submitOrderUrl, params);

	let cancelOrder = (params = {}) => vm.$u.post(cancelOrderUrl, params);

	let orderList = (params = {}) => vm.$u.post(orderListUrl, params);

	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {
		getSearch,
		getInfo,
		smsSend,
		userMobileLogin,
		userProfile,
		getUserInfo,
		userLogout,
		carList,
		carsDetail,
		getCarCategory,
		submitOrder,
		cancelOrder,
		orderList
	};
}

export default {
	install
}
